#-*- coding: utf-8 -*-
'''
Created on Aug 27, 2012

@author: bbg
'''

from sqlalchemy import Integer, Column, String, MetaData, Table
from sqlalchemy.orm import mapper
    
class ConfigPrinters(object):

    _Mapper_ = None
    _company_id_ = -1
    _shop_id_ = -1    
    def __init__(self):
        self.name = ''
        self.kitchen_name = ''
        self.ip = ''
        self.print_list = ''
        self.print_or = 0
        self.total_name = ''
        
    @staticmethod
    def doMapping(company_id, shop_id):
        '''
        按company_id分库，shop_id对应公司分店，每次生成对象前都要执行一次，以便map到正确的数据库上去
        '''
        if ConfigPrinters._company_id_ == company_id and ConfigPrinters._shop_id_ == shop_id:
            return
                
        if ConfigPrinters._Mapper_ is not None:
            ConfigPrinters._Mapper_.dispose()
            
        metaData = MetaData()
        configPrintersTable = Table('config_printers', metaData,
                           Column('id', Integer, primary_key = True),
                           Column('name', String),
                           Column('kitchen_name', String),
                           Column('ip', String),
                           Column('print_list', String),
                           Column('print_or', Integer),
                           Column('total_name', String),
                           schema = "shop_%s_%s" % (company_id, shop_id))
        
        ConfigPrinters._Mapper_ = mapper(ConfigPrinters, configPrintersTable)
    
